package com.zhishiku.filesystem.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@FeignClient(name = "chat-client", url = "${ai.address}")
public interface ChatFeign {

    /**
     * 聊天
     * @param chatId
     * @param authorization
     * @param request
     * {
     *     "question":string
     *     "stream":boolean
     *     "session_id"：（可选）string
     *     "user_id：（可选）string
     * }
     * @return
     */
    @PostMapping(
            value = "/api/v1/chats/{chat_id}/completions",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> sendCompletion(
            @PathVariable("chat_id") String chatId,
            @RequestHeader("Authorization") String authorization,
            @RequestBody Map<String,Object> request
    );



    /**
     * 创建会话
     * @param chatId
     * @param authorization
     * @param requestBody
     * {
     *     "name":string
     *     "user_id"：（可选）string
     * }
     * @return
     */
    @PostMapping(
            value = "/api/v1/chats/{chat_id}/sessions",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> createSession(
            @PathVariable("chat_id") String chatId,
            @RequestHeader("Authorization") String authorization,
            @RequestBody Map<String, Object> requestBody
    );


    /**
     * 更新会话
     * @param chatId
     * @param sessionId
     * @param authorization
     * @param requestBody
     * {
     *     "name:string
     *     "user_id：（可选）string
     * }
     * @return
     */
    @PutMapping(
            value = "/api/v1/chats/{chat_id}/sessions/{session_id}",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> updateSession(
            @PathVariable("chat_id") String chatId,
            @RequestHeader("Authorization") String authorization,
            @PathVariable("session_id") String sessionId,
            @RequestBody Map<String, Object> requestBody
    );



    /**
     * 列出聊天助手的会话
     * @param chatId
     * @param authorization
     * @param page
     * @param pageSize
     * @param orderBy
     * @param desc
     * @param name
     * @param id
     * @return
     */
    @GetMapping(
            value = "/api/v1/chats/{chat_id}/sessions",
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> getSessions(
            @PathVariable("chat_id") String chatId,
            @RequestHeader("Authorization") String authorization,
            @RequestParam(value = "user_id", required = false) String user_id
    );


    /**
     * 获取聊天助手的会话
     * @param chatId
     * @param authorization
     * @param id
     * @return
     */
    @GetMapping(
            value = "/api/v1/chats/{chat_id}/sessions",
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> getSession(
            @PathVariable("chat_id") String chatId,
            @RequestHeader("Authorization") String authorization,
            @RequestParam(value = "id", required = false) String sessionId,
            @RequestParam(value = "user_id", required = false) String user_id
    );



    /**
     * 删除聊天助手的会话
     * @param chatId
     * @param authorization
     * @param requestBody
     * {
     *     "ids":list[string]
     * }
     * @return
     */
    @DeleteMapping(
            value = "/api/v1/chats/{chat_id}/sessions",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    Map<String, Object> deleteSessions(
            @PathVariable("chat_id") String chatId,
            @RequestHeader("Authorization") String authorization,
            @RequestBody Map<String, Object> requestBody
    );


}
